package priv.mill.ss;

public class StackX {
	private int maxSize; // 栈的最大值
	private long[] stackArray;
	private int top; // 栈顶
	// --------------------------------------------------------------

	public StackX(int s) {
		maxSize = s; // 设置栈容量
		stackArray = new long[maxSize]; // 创建栈
		top = -1; // 初始化栈顶
	}

	public void push(long j) {
		stackArray[++top] = j;
	}

	public long pop() {
		return stackArray[top--];
	}

	public long peek() {
		return stackArray[top];
	}

	public boolean isEmpty() {
		return (top == -1);
	}

	public boolean isFull() {
		return (top == maxSize - 1);
	}

	public static void main(String[] args) {
		StackX theStack = new StackX(10); 
		theStack.push(20); // 入栈
		theStack.push(40);
		theStack.push(60);
		theStack.push(80);

		while (!theStack.isEmpty()) 
		{ 
			long value = theStack.pop();
			System.out.print(value); 
			System.out.print(" ");
		} 
		System.out.println("");
		//80 60 40 20 
	} 
}
